cmake_minimum_required(VERSION 3.10)

project(IGT_GASU VERSION 1.0)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 将目录放进变量中
set(INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)
set(SRC_DIR ${PROJECT_SOURCE_DIR}/src)

include_directories(${INCLUDE_DIR})

# Log 模块
aux_source_directory(${SRC_DIR}/Log LOG_LIB)
add_library(LogLib ${LOG_LIB})

# DDS 模块
include_directories(${INCLUDE_DIR}/Fast-DDS/include)
include_directories(${INCLUDE_DIR}/DDS)

link_directories(${PROJECT_SOURCE_DIR}/lib/Fast-DDS/install/lib)
set(DDS_Libs fastrtps fastcdr)

file(GLOB DDS_cpp "${SRC_DIR}/DDS/*.cpp" "${SRC_DIR}/DDS/*.ipp" "${SRC_DIR}/DDS/*.cxx")
add_library(DDSLib ${DDS_cpp})

# modbus 模块
aux_source_directory(${SRC_DIR}/ModBus GASU_MODBUS_LIB)
add_library(ModBusLib ${GASU_MODBUS_LIB})

# socket 模块
#aux_source_directory(${SRC_DIR}/SocketObj SOCKETS_LIB)
#add_library(SocketLib ${SOCKETS_LIB})

# fanuc 模块
aux_source_directory(${SRC_DIR}/SocketObj SOCKETS_LIB)
aux_source_directory(${SRC_DIR}/Fanuc FANUC_LIB)
add_library(FanucLib ${SOCKETS_LIB} ${FANUC_LIB})

include_directories(/usr/include)
find_library(MODBUS_LIB modbus PATHS /usr/lib/x86_64-linux-gnu)
if(NOT MODBUS_LIB)
    message(FATAL_ERROR "library modbus not find!")
endif()

add_executable(IGT_GASU main.cpp ${SRC_DIR}/GASU.cpp)

# 将可执行文件输出到 bin 目录
set_target_properties(IGT_GASU PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

target_link_libraries(IGT_GASU LogLib ModBusLib DDSLib FanucLib ${MODBUS_LIB} ${DDS_Libs} pthread)

# 创建log目录
# file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/bin/Log)

install(TARGETS IGT_GASU DESTINATION bin)
install(DIRECTORY /usr/include/modbus DESTINATION include)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/lib/ DESTINATION lib)

# 设置CPack配置
set(CPACK_PACKAGE_NAME "IGT_GASU")
set(CPACK_PACKAGE_VERSION "1.0.0")
set(CPACK_PACKAGE_DESCRIPTION "GASU")
set(CPACK_PACKAGE_VENDOR "IGT")
set(CPACK_PACKAGE_CONTACT "your-email@example.com")

# 包含安装包生成规则
include(CPack)